//
//  LSMineTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/19.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSMineTableViewCell.h"

@interface LSMineTableViewCell ()
@property (nonatomic, strong) UIImageView *mainImageView;
@property (nonatomic, strong) UILabel *mainTitleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;
@end

@implementation LSMineTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.mainImageView];
        [self.contentView addSubview:self.mainTitleLabel];
        [self.contentView addSubview:self.rightArrowImageView];
        [self.contentView addSubview:self.subTitleLabel];
        WS
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(0, 35));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        }];
        [self.subTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.rightArrowImageView.mas_left).with.offset(-10);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.width.mas_equalTo(ScreenWidth/2);
        }];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)setImageName:(NSString *)imageName {
    _imageName = imageName;
    WS
    if (![imageName isEqualToString:@""]) {
        self.mainImageView.image = [UIImage imageNamed:imageName];
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(44/2, 44/2));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mainImageView.mas_right).with.offset(10);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        }];
    } else {
        self.mainImageView.image = nil;
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(0, 44/2));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        }];
    }
}

- (void)setTitleLabelName:(NSString *)titleLabelName {
    _titleLabelName = titleLabelName;
    self.mainTitleLabel.text = titleLabelName;
}

- (void)setSubTitleLabelName:(NSString *)subTitleLabelName {
    _subTitleLabelName = subTitleLabelName;
    self.subTitleLabel.text = subTitleLabelName;
}

- (UIImageView *)mainImageView {
    if (!_mainImageView) {
        _mainImageView = [[UIImageView alloc] init];
    }
    return _mainImageView;
}

- (UILabel *)mainTitleLabel {
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
        _mainTitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:16];
        _mainTitleLabel.textColor = hexColor(666666);
    }
    return _mainTitleLabel;
}

- (UILabel *)subTitleLabel {
    if (!_subTitleLabel) {
        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
        _subTitleLabel.textColor = hexColor(666666);
        _subTitleLabel.textAlignment = NSTextAlignmentRight;
    }
    return _subTitleLabel;
}

- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"jiantou"] changeWithNewTintColor:hexColor(999999)]];
        _rightArrowImageView.center = CGPointMake(ScreenWidth-20, LSMineTableViewCellHeight/2);
    }
    return _rightArrowImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
